#include "main_window.h"
#include "structure_amova.h"
#include "structure_gst.h"

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
    _theProject = new Project();

    createUI();
    createActions();
    createMenus();


}

void MainWindow::createUI() {
    _displayWidget = new QWidget();
    _treeWidget = new QTreeWidget();
    _treeWidget->setColumnCount(1);
    _treeWidget->setAlternatingRowColors(true);
    _treeWidget->setHeaderHidden(true);
    _theProject->setTreeWidget( _treeWidget );


    _mainSplitter = new QSplitter();
    _mainSplitter->addWidget( _treeWidget );
    _mainSplitter->addWidget( _displayWidget );
    setCentralWidget( _mainSplitter );

}

void MainWindow::createActions() {

    _newAction = new QAction(tr("&New"),this);
    _newAction->setShortcut(tr("&New"));
    connect( _newAction, SIGNAL(triggered()), this, SLOT(slotNew()));

    _importDataAction = new QAction(tr("&Import"),this);
    _importDataAction->setShortcut(tr("CTRL+I"));
    connect( _importDataAction, SIGNAL(triggered()), _theProject, SLOT(slotImportGenotypes()));

    _quitAction = new QAction(tr("E&xit"),this);
    _quitAction->setShortcut(tr("CTRL+Q"));
    connect( _quitAction, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));

    _analysisGST = new QAction("&Gst",this);
    connect( _analysisGST, SIGNAL(triggered()), _theProject, SLOT(slotRunGst()));

    _analysisAMOVA = new QAction("&AMOVA",this);
    connect( _analysisAMOVA, SIGNAL(triggered()), _theProject, SLOT(slotRunAMOVA()));

}

void MainWindow::createMenus(){
    QMenu *fileMenu = this->menuBar()->addMenu(tr("&File"));
    fileMenu->addAction( _importDataAction );
    fileMenu->addAction(_quitAction);

    QMenu *analysisMenu = menuBar()->addMenu(tr("Analyses"));
    analysisMenu->addAction( _analysisAMOVA );
    analysisMenu->addAction( _analysisGST );
}


/**************************************************************
 *                                                            *
 *                          SLOTS                             *
 *                                                            *
 **************************************************************/

void MainWindow::slotNew() {
    MainWindow *w = new MainWindow(this);
    w->show();
}

void MainWindow::slotRunAMOVA() {

}

void MainWindow::slotRunGST() {

}
